home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / SNNSV32.ZIP / SNNSv3.2 / xgui / sources / bn_bighop.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-25  |  34.5 KB  |  1,295 lines

  1. /*****************************************************************************
  2.   FILE           : bn_bighop.c
  3.   SHORTNAME      : bn_bighop
  4.   SNNS VERSION   : 3.2
  5.  
  6.   PURPOSE        : Creates the Hopfield BIGNET-window. 
  7.   NOTES          :
  8.  
  9.   AUTHOR         : Christine Bagdi  
  10.   DATE           : 27.5.1993
  11.  
  12.   CHANGED BY     : 
  13.   IDENTIFICATION : @(#)bn_bignet.c    1.10 4/26/93
  14.   SCCS VERSION   : 1.10
  15.   LAST CHANGE    : 
  16.  
  17.              Copyright (c) 1990-1994  SNNS Group, IPVR, Univ. Stuttgart, FRG
  18.  
  19. ******************************************************************************/
  20.  
  21. #include <stdlib.h>
  22. #include <stdio.h>
  23. #include <X11/Xlib.h>
  24. #include <X11/Xutil.h>
  25. #include <X11/Xos.h>
  26. #include <X11/cursorfont.h>
  27. #include <X11/Intrinsic.h>
  28. #include <X11/StringDefs.h>
  29. #include <X11/Shell.h>
  30. #include <X11/Xaw/Box.h>
  31. #include <X11/Xaw/Simple.h>
  32. #include <X11/Xaw/Grip.h>
  33. #include <X11/Xaw/Form.h>
  34. #include <X11/Xaw/SmeBSB.h>
  35. #include <X11/Xaw/SmeLine.h>
  36. #include <X11/Xaw/Viewport.h>
  37. #include <X11/Xaw/Label.h>
  38. #include <X11/Xaw/Toggle.h>
  39. #include <X11/Xaw/Command.h>
  40. #include <X11/Xaw/Cardinals.h>
  41. #include <X11/Xaw/AsciiText.h>
  42. #include <X11/Xaw/Scrollbar.h>
  43.  
  44. #include "ui.h"
  45. #include "glob_typ.h"
  46. #include "kr_ui.h"
  47. #include "ui_mainP.h"
  48. #include "ui_confirmer.h"
  49. #include "ui_textP.h"
  50. #include "ui_utilP.h"
  51. #include "ui_netUpdate.h"
  52.  
  53. #include "ui_status.h"
  54. #include "ui_xWidgets.h"
  55. #include "ui_fileP.h"
  56. #include "ui_display.h"
  57. #include "ui_event.h"
  58. #include "ui_selection.h"
  59. #include "ui_action.h"
  60. #include "bn_basics.h"
  61.  
  62.  
  63. #include "bn_bighop.ph"
  64.  
  65.  
  66. /*************************************************************************
  67.  
  68.      File bn_create_net 
  69.  
  70. ***************************************************************************/
  71.  
  72. /*****************************************************************************
  73.   FUNCTION : bn_createPlanePanel
  74.  
  75.   PURPOSE  : creates the plane panel, which is part of the bignet-window
  76.   NOTES    :
  77.   RETURNS  :
  78.   UPDATE   : 20.12.1991
  79. ******************************************************************************/
  80.  
  81. static void bn_createPlanePannel (Widget parent)
  82.  
  83. {
  84.     Widget pannel;
  85.     Widget plane_edit,current_plane;
  86.     Widget plane_enter,plane_delete,plane_insert,plane_overwrite,plane_to_edit,type,pos;
  87.     Widget plane_first,plane_last,plane_prev,plane_next;
  88.     Widget       dummy;
  89.     Arg          arg[25];
  90.     Cardinal     n;
  91.     int colom1 = 25, colom2 = 13, colom3 = 10;
  92.  
  93.     n = 0;
  94.  
  95.     pannel = XtCreateManagedWidget ("pannel", formWidgetClass, parent, arg, n);
  96.  
  97.     z1s1 = ui_xCreateLabelItem ("           Plane           ", pannel, colom1 * bn_fontWidth, NULL, NULL);
  98.     z1s2 = ui_xCreateLabelItem ("Current Plane  ", pannel, colom2 * bn_fontWidth, z1s1, NULL);
  99.     z1s3 = ui_xCreateLabelItem ("Edit Plane  ", pannel, colom3 * bn_fontWidth, z1s2, NULL);
  100.  
  101.     z2s1   = ui_xCreateLabelItem ("Plane: ", pannel, colom1 * bn_fontWidth, NULL, z1s1);
  102.     dummy = ui_xCreateLabelItem (" ", pannel, 3 * bn_fontWidth, z2s1, z1s1);
  103.     z2s2   = ui_xCreateFrameLabelItem ("", pannel,bn_intWidth,dummy,z1s1);
  104.  
  105.     z3s1  = ui_xCreateLabelItem ("Type: ",pannel,colom1 * bn_fontWidth,NULL,z2s1);
  106.     dummy = ui_xCreateLabelItem (" ",pannel,3 * bn_fontWidth,z3s1,z2s1);
  107.     z3s2  = ui_xCreateFrameLabelItem ("",pannel,bn_intWidth,dummy,z2s1);
  108.     dummy = ui_xCreateLabelItem (" ",pannel,5 * bn_fontWidth,z3s2,z2s1);
  109.     z3s3  = ui_xCreateFrameLabelItem (plane_type[PLANE_type],pannel,bn_intWidth,dummy,z2s1);
  110.  
  111.     z4s1  = ui_xCreateLabelItem ("No. of units in x-direction: ",pannel,colom1 * bn_fontWidth,NULL,z3s1);
  112.     dummy = ui_xCreateLabelItem (" ", pannel, 3 * bn_fontWidth,z4s1,z3s1);
  113.     z4s2  = ui_xCreateFrameLabelItem ("", pannel,bn_intWidth,dummy,z3s1);
  114.     dummy = ui_xCreateLabelItem (" ", pannel, 5 * bn_fontWidth,z4s2,z3s1);
  115.     z4s3  = ui_xCreateDialogItem ("z4s3", pannel,"",bn_intWidth,dummy,z3s1);
  116.  
  117.     z5s1  = ui_xCreateLabelItem ("No. of units in y-direction: ",pannel,colom1 * bn_fontWidth,NULL,z4s1);
  118.     dummy = ui_xCreateLabelItem (" ", pannel, 3 * bn_fontWidth,z5s1,z4s1);
  119.     z5s2  = ui_xCreateFrameLabelItem ("", pannel,bn_intWidth,dummy,z4s1);
  120.     dummy = ui_xCreateLabelItem (" ", pannel, 5 * bn_fontWidth,z5s2,z4s1);
  121.     z5s3  = ui_xCreateDialogItem ("z4s3", pannel, "",bn_intWidth,dummy,z4s1);
  122.  
  123.     z6s1  = ui_xCreateLabelItem ("z-coordinates of the plane: ",pannel,colom1 * bn_fontWidth,NULL,z5s1);
  124.     dummy = ui_xCreateLabelItem (" ",pannel,3 * bn_fontWidth,z6s1,z5s1);
  125.     z6s2  = ui_xCreateFrameLabelItem ("", pannel,bn_intWidth,dummy,z5s1);
  126.     dummy = ui_xCreateLabelItem (" ",pannel,5 * bn_fontWidth,z6s2,z5s1);
  127.     z6s3  = ui_xCreateDialogItem ("z4s3",pannel,"",bn_intWidth,dummy,z5s1);
  128.  
  129.     z7s1  = ui_xCreateLabelItem ("Rel. Position: ",pannel,colom1 * bn_fontWidth,NULL,z6s1);
  130.     dummy = ui_xCreateLabelItem (" ",pannel,3 * bn_fontWidth,z7s1,z6s1);
  131.     z7s2  = ui_xCreateFrameLabelItem ("", pannel,bn_intWidth,dummy,z6s1);
  132.     dummy = ui_xCreateLabelItem (" ",pannel,5 * bn_fontWidth,z7s2,z6s1);
  133.     z7s3  = ui_xCreateFrameLabelItem (plane_pos[PLANE_pos],pannel,bn_intWidth,dummy,z6s1);
  134.  
  135.     dummy         = ui_xCreateLabelItem (" ",pannel,15 * bn_fontWidth,NULL,z7s1);
  136.  
  137.     plane_edit = ui_xCreateLabelItem ("Edit Plane: ",pannel,15 * bn_fontWidth,NULL,dummy);
  138.     plane_enter      = bn_basics_xCreateButtonItem ("enter",pannel,plane_edit,dummy);
  139.       XtAddCallback(plane_enter,XtNcallback,(XtCallbackProc)enter_plane_PROC,NULL);
  140.     plane_insert     = bn_basics_xCreateButtonItem ("insert",pannel,plane_enter,dummy);
  141.       XtAddCallback(plane_insert,XtNcallback,(XtCallbackProc)insert_plane_PROC,NULL);
  142.     plane_overwrite  = bn_basics_xCreateButtonItem ("overwrite",pannel,plane_insert,dummy);
  143.  
  144.       XtAddCallback(plane_overwrite,XtNcallback,(XtCallbackProc)overwrite_plane_PROC,NULL);
  145.     plane_delete     = bn_basics_xCreateButtonItem ("delete",pannel,plane_overwrite,dummy);
  146.       XtAddCallback(plane_delete,XtNcallback,(XtCallbackProc)delete_plane_PROC,NULL);
  147.  
  148.     dummy         = ui_xCreateLabelItem (" ",pannel,15 * bn_fontWidth,NULL,plane_edit);
  149.     plane_to_edit = bn_basics_xCreateButtonItem ("plane_to_edit",pannel,dummy,plane_edit);
  150.       XtAddCallback(plane_to_edit,XtNcallback,(XtCallbackProc)current_plane_to_editor_PROC,NULL);
  151.     type          = bn_basics_xCreateButtonItem ("type",pannel,plane_to_edit,plane_edit);
  152.       XtAddCallback(type,XtNcallback,(XtCallbackProc)type_PROC,NULL);
  153.     pos           = bn_basics_xCreateButtonItem ("pos",pannel,type,plane_edit);
  154.       XtAddCallback(pos,XtNcallback,(XtCallbackProc)pos_PROC,NULL);
  155.  
  156.     current_plane = ui_xCreateLabelItem ("Current plane: ",pannel,15 * bn_fontWidth,NULL,dummy);
  157.     plane_first         = bn_basics_xCreateButtonItem ("first",pannel,current_plane,dummy);
  158.       XtAddCallback(plane_first,XtNcallback,(XtCallbackProc)beginning_plane_PROC,NULL);
  159.     plane_prev          = bn_basics_xCreateButtonItem ("prev",pannel,plane_first,dummy);
  160.       XtAddCallback(plane_prev,XtNcallback,(XtCallbackProc)backward_plane_PROC,NULL);
  161.     plane_next          = bn_basics_xCreateButtonItem ("next",pannel,plane_prev,dummy);
  162.       XtAddCallback(plane_next,XtNcallback,(XtCallbackProc)forward_plane_PROC,NULL);
  163.     plane_last          = bn_basics_xCreateButtonItem ("last",pannel,plane_next,dummy);
  164.       XtAddCallback(plane_last,XtNcallback,(XtCallbackProc)end_plane_PROC,NULL);
  165. }
  166.  
  167.  
  168. /*****************************************************************************
  169.   FUNCTION : exit_PROC
  170.  
  171.   PURPOSE  : callback function of the exit-button. You are leaving bignet.
  172.   NOTES    :
  173.   RETURNS  :
  174.  
  175.   UPDATE   : 27.05.1993
  176. ******************************************************************************/
  177.  
  178. static void exit_PROC (void)
  179.  
  180. {
  181.     XtDestroyWidget (baseWidget);
  182.     bighop_widget_open = 0;
  183. }
  184. /* chris */
  185. /*****************************************************************************
  186.   FUNCTION : bn_createBigHop
  187.  
  188.   PURPOSE  : creates the bignet-window.
  189.   NOTES    : 
  190.   RETURNS  :
  191.  
  192.   UPDATE   : 27.05.1993
  193. ******************************************************************************/
  194.  
  195. void bn_createBigHop (void)
  196.  
  197. {
  198.     Widget       box;
  199.     Widget       create_net,exit,cancel;
  200.     Arg          arg[25];
  201.     Cardinal     n;
  202.     char         buf[40];
  203.  
  204.     if(! bighop_widget_open)
  205.       {
  206.        sprintf (buf, "BigNet (Hopfield)");
  207.        n = 0;  
  208.  
  209.        XtSetArg(arg[n],XtNminHeight,699); n++;
  210.        XtSetArg(arg[n],XtNminWidth,410); n++;  
  211.        XtSetArg(arg[n],XtNmaxHeight,699); n++;
  212.        XtSetArg(arg[n],XtNmaxWidth,410); n++;
  213.        
  214.  
  215.        baseWidget = XtCreatePopupShell (buf, topLevelShellWidgetClass, ui_toplevel, arg, n); 
  216.        n = 0;  
  217.        box = XtCreateManagedWidget ("box", boxWidgetClass, baseWidget, arg, n);
  218.        bn_createPlanePannel (box); 
  219.  
  220.        create_net = bn_basics_xCreateButtonItem ("create_net",box,NULL,NULL);
  221.          XtAddCallback(create_net,XtNcallback,(XtCallbackProc)create_net_PROC,NULL);
  222.        exit = bn_basics_xCreateButtonItem ("done",box,create_net,NULL);
  223.        XtAddCallback(exit,XtNcallback,(XtCallbackProc)exit_PROC,NULL);
  224.        cancel     = bn_basics_xCreateButtonItem ("cancel",box,exit,NULL);
  225.        XtAddCallback(cancel,XtNcallback,(XtCallbackProc)cancel_net_PROC,NULL);
  226.  
  227.        ui_checkWindowPosition(baseWidget);
  228.        XtPopup (baseWidget, XtGrabNone);
  229.        bighop_widget_open = 1;
  230.        if(PLANE_length != 0){
  231.          write_current_plane();
  232.          }
  233.  
  234.      } else {
  235.     
  236.         ui_confirmOk ("BigNet (Hopfield) already loaded");
  237.  
  238.      }
  239. }
  240.  
  241.  
  242.    
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250. /*************************************************************************
  251.  
  252.      File bn_create_net 
  253.  
  254. ***************************************************************************/
  255.  
  256.  
  257. /*****************************************************************************
  258.   FUNCTION : create__net_PROC
  259.  
  260.   PURPOSE  : creates a SNNS-net in two steps:
  261.              1. calls up a function, which creates SNNS-units
  262.              2. calls up a function, which connects the SNNS-units.
  263.   NOTES    : There is a full connection of the units! ( Clique ) 
  264.              
  265.   RETURNS  :
  266.  
  267.   UPDATE   : 27.05.1993
  268. ******************************************************************************/
  269.  
  270. static void create_net_PROC(void)
  271.  
  272. {
  273.  PLANE *source_plane,*target_plane;
  274.  int move;
  275.  int create=1;
  276.  
  277.  BN_ERROR = 0;
  278.  
  279.  if(krui_getNoOfUnits() != 0) {
  280.    if(! ui_confirmYes("Create will erase current network. Create?")) {
  281.      create = 0;
  282.    }
  283.  }
  284.  
  285.  if(create && (PLANE_length != 0)) {
  286.  
  287.    krui_deleteNet();
  288.  
  289.    calculate_first_snns_unit_no_of_plane();
  290.    create_snns_unit(); 
  291.    make_links();
  292.    krui_setLearnFunc("BPTT");
  293.    krui_setUpdateFunc("Hopfield_Synchronous");
  294.    krui_setInitialisationFunc("ClippHebb");
  295.    bn_display_net();
  296.  }/* if */ 
  297. }
  298.  
  299. /*****************************************************************************
  300.   FUNCTION : calculate_first_snns_unit_no_of_plane
  301.  
  302.   PURPOSE  : calculates the SNNS unit no of the left upper corner of every
  303.              plane.
  304.   NOTES    : relative to this unit no, knowing the width and the height of the
  305.              planes, all other SNNS unit numbers of every plane can be 
  306.              calculated. That's important for the function create_snns_unit.
  307.   RETURNS  :
  308.  
  309.   UPDATE   : 20.12.1991
  310. ******************************************************************************/
  311.  
  312. static void calculate_first_snns_unit_no_of_plane(void)
  313.  
  314. {
  315.  PLANE *PLANE_element = PLANE_first_element;
  316.  
  317.  (*PLANE_element).begin = 1;  
  318.  PLANE_element = (*PLANE_element).next;
  319.  
  320.  while(PLANE_element != NULL) {
  321.    (*PLANE_element).begin = (*(*PLANE_element).before).width *
  322.                                 (*(*PLANE_element).before).height +
  323.                   (*(*PLANE_element).before).begin;
  324.    PLANE_element = (*PLANE_element).next; 
  325.  }
  326. }
  327.  
  328.  
  329.  
  330. /*****************************************************************************
  331.   FUNCTION : calculate_x_begin
  332.  
  333.   PURPOSE  : calculates the x-coordinate of a plane, where the plane is
  334.              positioned in the display window.
  335.              plane.
  336.   NOTES    : 
  337.   RETURNS  : The X-Position
  338.  
  339.   UPDATE   : 20.12.1991
  340. ******************************************************************************/
  341.  
  342.  
  343. static int calculate_x_begin(int *new_x_begin,int *old_x_begin,int *x_max,int width,int pos)
  344.  
  345. {
  346.  if(pos == BN_RIGHT) {
  347.    
  348.    *new_x_begin = *x_max + 2; 
  349.    *x_max = *new_x_begin + width;
  350.    *old_x_begin = *new_x_begin;
  351.    return *new_x_begin;
  352.  }
  353.  else if(pos == BN_BELOW) {
  354.    if(*x_max < (*old_x_begin + width)) {
  355.      *x_max = *old_x_begin + width;
  356.    }
  357.    return *old_x_begin; 
  358.  }
  359.  else if(pos == BN_LEFT) {
  360.    *x_max = 0;
  361.    *old_x_begin = 2;
  362.  
  363.    *new_x_begin = *x_max + 2;
  364.    *x_max = *new_x_begin + width;
  365.    return *new_x_begin;
  366.  }
  367.  return 0;
  368. }
  369.  
  370.  
  371. /*****************************************************************************
  372.   FUNCTION : calculate_y_begin
  373.  
  374.   PURPOSE  : calculates the y-coordinate of a plane, where the plane is
  375.              positioned in the display window.
  376.              plane.
  377.  
  378.   NOTES    : 
  379.   RETURNS  : The Y-Position
  380.  
  381.   UPDATE   : 20.12.1991
  382. ******************************************************************************/
  383.  
  384. static int calculate_y_begin(int *absolute_y_max,int *relative_y_max,int *y_offset,int height,int pos)
  385.  
  386. {
  387. int y_begin;
  388.  
  389.  if(pos == BN_RIGHT) {
  390.    y_begin = *y_offset + 2;         
  391.    *relative_y_max = y_begin + height;
  392.    if(*absolute_y_max < *relative_y_max) {
  393.      *absolute_y_max = *relative_y_max;
  394.    }
  395.  }
  396.  else if(pos == BN_BELOW) {
  397.    y_begin = *relative_y_max + 2;   
  398.    *relative_y_max = y_begin + height;
  399.    if(*absolute_y_max < *relative_y_max) {
  400.      *absolute_y_max = *relative_y_max;
  401.    }
  402.  }
  403.  else if(pos == BN_LEFT) {
  404.    *y_offset = *absolute_y_max;
  405.    y_begin = *y_offset + 2;
  406.    *absolute_y_max = y_begin + height;
  407.    *relative_y_max = y_begin + height;
  408.  }
  409.  return y_begin;
  410. }
  411.  
  412.  
  413. /*****************************************************************************
  414.   FUNCTION : create_snns_unit
  415.  
  416.   PURPOSE  : creates for every unit of a plane a SNNS  unit.
  417.  
  418.   NOTES    : Default unit with Step - activation function
  419.   RETURNS  :
  420.  
  421.   UPDATE   : 20.12.1991
  422. ******************************************************************************/
  423.  
  424. static void create_snns_unit(void)
  425.  
  426. {
  427.  struct PosType unit_pos;
  428.  
  429.  PLANE *PLANE_element = PLANE_first_element; 
  430.  int x,y,width,height,unit_no,pos,ret;
  431.  int y_offset=0,relative_y_max=0,absolute_y_max=0,y_begin;
  432.  int x_max=0,old_x_begin=2,new_x_begin,x_begin;
  433.  
  434.  ret = krui_allocateUnits((*PLANE_last_element).width * 
  435.                              (*PLANE_last_element).height +
  436.                                (*PLANE_last_element).begin-1);
  437.  if(ret != 0){
  438.    ui_tw_errorMessage(krui_error(ret));
  439.    BN_ERROR = 1;
  440.  }
  441.  
  442.  while((! BN_ERROR) && (PLANE_element != NULL)) {
  443.  
  444.    height = (*PLANE_element).height;
  445.    width  = (*PLANE_element).width;
  446.    pos    = (*PLANE_element).pos;
  447.     
  448.    y_begin = calculate_y_begin(&absolute_y_max,&relative_y_max,&y_offset,height,pos);
  449.    x_begin = calculate_x_begin(&new_x_begin,&old_x_begin,&x_max,width,pos);
  450.  
  451.    for(y=0;y<height;y++){
  452.      for(x=0;x<width;x++){
  453.        unit_no = krui_createDefaultUnit();
  454.        if(unit_no<0) ui_checkError(unit_no);
  455.        krui_setUnitActFunc(unit_no, "Act_Perceptron");
  456.        ret = krui_setUnitTType(unit_no,(*PLANE_element).type+1);
  457.        if(ret != 0){
  458.          ui_tw_errorMessage(krui_error(ret));
  459.          BN_ERROR = 1;
  460.        }
  461.       
  462.        unit_pos.x = x_begin + x;
  463.        unit_pos.y = y_begin + y;
  464.  
  465.        krui_setUnitPosition(unit_no,&unit_pos);
  466.      }/*for*/
  467.    }/*for*/
  468.  
  469.    PLANE_element = (*PLANE_element).next;
  470.  }/*while*/
  471. }
  472.  
  473.  
  474. /*****************************************************************************
  475.   FUNCTION : make_links
  476.  
  477.   PURPOSE  : Insert Links between all units, that they form a
  478.              clique, i.e. every unit is connected to all other units.
  479.   RETURNS  : alteration of the network
  480.   NOTES    :
  481.  
  482.   UPDATE   :
  483. *****************************************************************************/
  484.  
  485. static void make_links(void)
  486.  
  487. {
  488.   int                     unit_ptr, mainUnit_Ptr;
  489.   FlintType               weight;
  490.   
  491.   
  492.   
  493.   weight = 1.0;
  494.   
  495.   for ((mainUnit_Ptr) = krui_getFirstUnit();
  496.        (mainUnit_Ptr) <= krui_getNoOfUnits(); (mainUnit_Ptr)++)
  497.     
  498.     /* main loop  self connections too  */
  499.     
  500.     for ((unit_ptr) =  krui_getFirstUnit();
  501.      (unit_ptr) <= krui_getNoOfUnits(); (unit_ptr)++) { 
  502.       
  503.       
  504.       /* inner loop */
  505.       /*if (NOT (unit_ptr == mainUnit_Ptr)) {  not the same entry !! */
  506.       
  507.       krui_setCurrentUnit(mainUnit_Ptr);
  508.       if (NOT krui_isConnected(unit_ptr)) {
  509.     krui_createLink(unit_ptr, weight);
  510.     krui_setLinkWeight(weight); 
  511.     
  512.       }
  513.     }
  514. }
  515.  
  516.  
  517. /*****************************************************************************
  518.   FUNCTION : bn_display_net
  519.  
  520.   PURPOSE  : displays the created net in the display window of SNNS.
  521.  
  522.   NOTES    : 
  523.   RETURNS  :
  524.  
  525.   UPDATE   : 20.12.1991
  526. ******************************************************************************/
  527.  
  528. static void bn_display_net(void)
  529.  
  530. {
  531.  ui_sel_resetList();
  532.  ui_net_completeRefresh(ui_currentDisplay,2);
  533.  ui_stat_displayStatus(ui_gridPosMouse);
  534.  strcpy(ui_filenameNET,"SNNS_NET");
  535.  strcpy(ui_filenameSLNET,"SNNS_NET");
  536.  ui_file_updateShellLabels();
  537. }
  538.  
  539. /*****************************************************************************
  540.  
  541.   bn_plane
  542.   PURPOSE  : Functions of the plane editor.
  543.  
  544. ******************************************************************************/
  545.  
  546.  
  547. /*****************************************************************************
  548.   FUNCTION : read_plane_elements
  549.  
  550.   PURPOSE  : reads the input datas of the plane editor (Edit Plane).
  551.  
  552.   NOTES    : 
  553.  
  554.   RETURNS  :  Error = 0 ; Succes = 1
  555.  
  556.   UPDATE   : 20.12.1991
  557. ******************************************************************************/
  558.  
  559. static int read_plane_elements(void)
  560.  
  561. {
  562.  PLANE_width = ui_xIntFromAsciiWidget(z4s3);
  563.  PLANE_height = ui_xIntFromAsciiWidget(z5s3);
  564.  if((PLANE_width > 0) && (PLANE_height > 0)) {
  565.    return 1;
  566.  }
  567.  else {
  568.    return 0;
  569.  }
  570. }
  571.   
  572. /*****************************************************************************
  573.   FUNCTION : write_current_plane
  574.  
  575.   PURPOSE  : writes the datas of the current_element to the control part 
  576.              (Current Plane) of the plane editor.
  577.  
  578.   NOTES    : 
  579.   RETURNS  : 
  580.  
  581.   UPDATE   : 20.12.1991
  582. ******************************************************************************/
  583.  
  584. static void write_current_plane(void)
  585.  
  586.  {
  587.   char buf[10];
  588.  
  589.   sprintf(buf,"%d",PLANE_no);
  590.   ui_xSetLabel(z2s2,bn_widget_output(buf));
  591.   ui_xSetLabel(z3s2,plane_type[(*PLANE_current_element).type]);
  592.   sprintf(buf,"%d",(*PLANE_current_element).width);
  593.   ui_xSetLabel(z4s2,bn_widget_output(buf));
  594.   sprintf(buf,"%d",(*PLANE_current_element).height);
  595.   ui_xSetLabel(z5s2,bn_widget_output(buf));
  596.   sprintf(buf,"%d",0);
  597.   ui_xSetLabel(z6s2,bn_widget_output(buf));
  598.   ui_xSetLabel(z7s2,plane_pos[(*PLANE_current_element).pos]);
  599. }
  600.  
  601. /*****************************************************************************
  602.   FUNCTION : clear_current_plane
  603.  
  604.   PURPOSE  : Deletes the datas standing in Current Plane.
  605.  
  606.   NOTES    : 
  607.   RETURNS  :
  608.  
  609.   UPDATE   : 20.12.1991
  610. ******************************************************************************/
  611.  
  612. static void clear_current_plane(void)
  613.  
  614.  {
  615.   ui_xSetLabel(z2s2,"");
  616.   ui_xSetLabel(z3s2,"");
  617.   ui_xSetLabel(z4s2,"");
  618.   ui_xSetLabel(z5s2,"");
  619.   ui_xSetLabel(z6s2,"");
  620.   ui_xSetLabel(z7s2,"");
  621. }
  622.  
  623. /*****************************************************************************
  624.   FUNCTION : write_current_plane_to_editor
  625.  
  626.   PURPOSE  : writes the datas of Current Plane to Edit Plane
  627.  
  628.   NOTES    : 
  629.   RETURNS  :
  630.  
  631.   UPDATE   : 20.12.1991
  632. ******************************************************************************/
  633.  
  634. static void write_current_plane_to_editor(void)
  635.  
  636.  {
  637.   char buf[10];
  638.  
  639.   PLANE_type = (*PLANE_current_element).type;
  640.   ui_xSetLabel(z3s3,plane_type[PLANE_type]);
  641.   sprintf(buf,"%d",(*PLANE_current_element).width);
  642.   ui_xSetString(z4s3,bn_widget_output(buf));
  643.   sprintf(buf,"%d",(*PLANE_current_element).height);
  644.   ui_xSetString(z5s3,bn_widget_output(buf));
  645.   sprintf(buf,"%d",0);
  646.   ui_xSetString(z6s3,bn_widget_output(buf));
  647.   PLANE_pos = (*PLANE_current_element).pos;
  648.   ui_xSetLabel(z7s3,plane_pos[PLANE_pos]);
  649. }
  650.  
  651. /*****************************************************************************
  652.   FUNCTION : clear_edit_plane
  653.  
  654.   PURPOSE  : Deletes the datas standing in Edit Link.
  655.  
  656.   NOTES    : 
  657.   RETURNS  :
  658.  
  659.   UPDATE   : 20.12.1991
  660. ******************************************************************************/
  661.  
  662. static void clear_edit_plane(void)
  663.  
  664. {
  665.  ui_xSetString(z4s3,"");
  666.  ui_xSetString(z5s3,"");
  667.  ui_xSetString(z6s3,"");
  668.  
  669.  
  670. /*****************************************************************************
  671.   FUNCTION : cancel_net_PROC
  672.  
  673.   PURPOSE  : callback function, which deletes all the datas in the link 
  674.              editor and in the plane editor.
  675.  
  676.   NOTES    : 
  677.   RETURNS  :
  678.  
  679.   UPDATE   : 20.12.1991
  680. ******************************************************************************/
  681.  
  682. static void cancel_net_PROC(void)
  683.  
  684. {
  685.  while(PLANE_length){
  686.   delete_current_plane();
  687.  }
  688.  clear_current_plane();
  689. }
  690.  
  691. /*****************************************************************************
  692.   FUNCTION : enter_plane_PROC
  693.  
  694.   PURPOSE  : callback function, which enters a plane element at the end of the 
  695.              plane list.
  696.  
  697.   NOTES    : the plane list contains all datas entered by the plane editor.
  698.              Every plane element is a struct (see bn_types.c)
  699.   RETURNS  :
  700.  
  701.   UPDATE   : 20.12.1991
  702. ******************************************************************************/
  703.  
  704. static void enter_plane_PROC(void)
  705.  
  706. {
  707.  if(read_plane_elements()){
  708.    enter_plane();
  709.    write_current_plane();
  710.    clear_edit_plane();
  711.  }
  712. }
  713.  
  714. /*****************************************************************************
  715.   FUNCTION : insert_plane_PROC
  716.  
  717.   PURPOSE  : callback function, which inserts the the input datas of the
  718.              plane editor (Edit Plane) in front of Current Plane.
  719.  
  720.   NOTES    : 
  721.   RETURNS  :
  722.  
  723.   UPDATE   : 20.12.1991
  724. ******************************************************************************/
  725.  
  726. static void insert_plane_PROC(void)
  727.  
  728. {
  729.  if(read_plane_elements()) {
  730.    insert_plane();
  731.    write_current_plane();
  732.    clear_edit_plane();
  733. /*   if(LINK_length == 0) {
  734.      clear_current_link();
  735.    }
  736.    else {
  737.      write_current_link();
  738.    }
  739. */
  740.  }
  741. }
  742.  
  743. /*****************************************************************************
  744.   FUNCTION : overwrite_plane_PROC
  745.  
  746.   PURPOSE  : callback function, which overwrites the current plane element
  747.              (Current Plane) with the datas of the plane editor (Edit plane).
  748.  
  749.   NOTES    : 
  750.   RETURNS  :
  751.  
  752.   UPDATE   : 20.12.1991
  753. ******************************************************************************/
  754.  
  755. static void overwrite_plane_PROC(void)
  756.  
  757. {
  758.  if(read_plane_elements()) {
  759.   overwrite_plane();
  760.   write_current_plane();
  761.   clear_edit_plane();
  762. /*  if(LINK_length == 0) {
  763.     clear_current_link();
  764.   }
  765.   else {
  766.     write_current_link();
  767.   }
  768. */
  769.  }
  770. }
  771.  
  772. /*****************************************************************************
  773.   FUNCTION : delete_plane_PROC
  774.  
  775.   PURPOSE  : callback function, which deletes the Currenrt Plane out of
  776.              the plane list.
  777.  
  778.   NOTES    : 
  779.   RETURNS  :
  780.  
  781.   UPDATE   : 20.12.1991
  782. ******************************************************************************/
  783.  
  784. static void delete_plane_PROC(void)
  785.  
  786. {
  787.  delete_current_plane();
  788.  if(PLANE_length == 0) {
  789.    clear_current_plane();
  790.  }
  791.  else {
  792.    write_current_plane();
  793.  }
  794. /* if(LINK_length == 0) {
  795.    clear_current_link();
  796.  }
  797.  else {
  798.   write_current_link();
  799.  }
  800. */
  801. }
  802.  
  803. /*****************************************************************************
  804.   FUNCTION : forward_plane_PROC
  805.  
  806.   PURPOSE  : callback function, which moves forward one list element in the
  807.              plane list.
  808.  
  809.   NOTES    : 
  810.   RETURNS  :
  811.  
  812.   UPDATE   : 20.12.1991
  813. ******************************************************************************/
  814.  
  815. static void forward_plane_PROC(void)
  816.  
  817. {
  818.  if(forward_plane()){
  819.    write_current_plane();
  820.  }
  821. }
  822.  
  823. /*****************************************************************************
  824.   FUNCTION : backward_plane_PROC
  825.  
  826.   PURPOSE  : callback function, which moves backward one list element in the
  827.              plane list.
  828.  
  829.   NOTES    : 
  830.   RETURNS  :
  831.  
  832.   UPDATE   : 20.12.1991
  833. ******************************************************************************/
  834.  
  835. static void backward_plane_PROC(void)
  836.  
  837. {
  838.  if(backward_plane()) {
  839.    write_current_plane();
  840.  }
  841. }
  842.  
  843. /*****************************************************************************
  844.   FUNCTION : end_plane_PROC
  845.  
  846.   PURPOSE  : callback function, which jumps to the end of the plane list.
  847.  
  848.   NOTES    : 
  849.   RETURNS  :
  850.  
  851.   UPDATE   : 20.12.1991
  852. ******************************************************************************/
  853.  
  854. static void end_plane_PROC(void)
  855.  
  856. {
  857.  if(end_plane()) {
  858.    write_current_plane();
  859.  }
  860. }
  861.  
  862. /*****************************************************************************
  863.   FUNCNCTION : beginning_plane_PROC
  864.  
  865.   PURPOSE  : callback function, which jumps to the beginning of the plane list.
  866.  
  867.   NOTES    : 
  868.   RETURNS  :
  869.  
  870.   UPDATE   : 20.12.1991
  871. ******************************************************************************/
  872.  
  873. static void beginning_plane_PROC(void)
  874.  
  875. {
  876.  if(beginning_plane()) {
  877.    write_current_plane();
  878.  }
  879. }
  880.  
  881. /*****************************************************************************
  882.   FUNCNCTION : pos_PROC
  883.  
  884.   PURPOSE  : callback function, which defines the position of the plane in the
  885.              display window.
  886.  
  887.   NOTES    : 
  888.   RETURNS  :
  889.  
  890.   UPDATE   : 20.12.1991
  891. ******************************************************************************/
  892.  
  893. static void pos_PROC(void)
  894.  
  895. {
  896.  if(PLANE_pos == BN_RIGHT) {
  897.    PLANE_pos = BN_BELOW;
  898.  }
  899.  else if(PLANE_pos == BN_BELOW) {
  900.    PLANE_pos = BN_LEFT;
  901.  } 
  902.  else {
  903.    PLANE_pos = BN_RIGHT;
  904.  }
  905.  ui_xSetLabel(z7s3,plane_pos[PLANE_pos]);
  906. }
  907.  
  908. /*****************************************************************************
  909.   FUNCNCTION : current_plane_to_editor_PROC
  910.  
  911.   PURPOSE  : callback function, which writes the Current Plane to Edit Plane
  912.  
  913.   NOTES    : 
  914.   RETURNS  :
  915.  
  916.   UPDATE   : 20.12.1991
  917. ******************************************************************************/
  918.  
  919. static void current_plane_to_editor_PROC(void)
  920.  
  921. {
  922.  if(PLANE_length != 0) {
  923.    write_current_plane_to_editor();
  924.  }
  925.  else {
  926.    clear_edit_plane();
  927.  }
  928. }
  929.  
  930. /*****************************************************************************
  931.   FUNCNCTION : type_PROC
  932.  
  933.   PURPOSE  : callback function, which defines the unit type of a plane.
  934.  
  935.   NOTES    : 
  936.   RETURNS  :
  937.  
  938.   UPDATE   : 20.12.1991
  939. ******************************************************************************/
  940.  
  941. static void type_PROC(void)
  942.  
  943. {
  944.  switch(PLANE_type){
  945.    case BN_INPUT : {PLANE_type = BN_HIDDEN; break;}
  946.    case BN_HIDDEN: {PLANE_type = BN_OUTPUT; break;}
  947.    case BN_OUTPUT: {PLANE_type = BN_INPUT ; break;}
  948.    case BN_DUAL:   {PLANE_type = BN_DUAL  ; break;}  
  949.  }
  950.  ui_xSetLabel(z3s3,plane_type[PLANE_type]);
  951. }
  952.  
  953. /*****************************************************************************
  954.   FUNCTION : enter_plane
  955.  
  956.   PURPOSE  : enters a plane element at the end of the plane list.
  957.  
  958.   NOTES    : 
  959.   RETURNS  :
  960.  
  961.   UPDATE   : 20.12.1991
  962. ******************************************************************************/
  963.  
  964. static void enter_plane(void)
  965.  
  966. {
  967.  PLANE *PLANE_element;
  968.  
  969.  PLANE_element = (PLANE *)malloc(sizeof(PLANE));
  970.  (*PLANE_element).width      = PLANE_width;                                    
  971.  (*PLANE_element).height      = PLANE_height;
  972.  (*PLANE_element).pos    = PLANE_pos;
  973.  (*PLANE_element).type   = PLANE_type;                                    
  974.  (*PLANE_element).next   = NULL;                            
  975.  (*PLANE_element).before = PLANE_last_element;         
  976.  
  977.  if(PLANE_last_element != NULL) {
  978.    (*PLANE_last_element).next = PLANE_element;
  979.  }
  980.  
  981.  if(PLANE_first_element == NULL) {
  982.    PLANE_first_element = PLANE_element;
  983.  }
  984.  
  985.  PLANE_last_element = PLANE_element;
  986.  PLANE_current_element = PLANE_last_element;
  987.  
  988.  PLANE_no = ++PLANE_length;
  989. }/* enter_plane */
  990.  
  991. /*****************************************************************************
  992.   FUNCTION : insert_plane
  993.  
  994.   PURPOSE  : inserts the the input datas of the plane editor (Edit Plane) in 
  995.              front of Current Plane.
  996.  
  997.   NOTES    : 
  998.   RETURNS  :
  999.  
  1000.   UPDATE   : 20.12.1991
  1001. ******************************************************************************/
  1002.  
  1003. static void insert_plane(void)
  1004.  
  1005. {
  1006.  PLANE *PLANE_element;
  1007.  
  1008.  if(PLANE_length == 0) {
  1009.    enter_plane();
  1010.  }
  1011.  else {
  1012.    PLANE_element = (PLANE *)malloc(sizeof(PLANE));
  1013.    
  1014.    (*PLANE_element).width      = PLANE_width;                                    
  1015.    (*PLANE_element).height      = PLANE_height;
  1016.    (*PLANE_element).pos    = PLANE_pos;
  1017.    (*PLANE_element).type   = PLANE_type;                                    
  1018.    (*PLANE_element).next   = PLANE_current_element;                            
  1019.    (*PLANE_element).before = (*PLANE_current_element).before;
  1020.  
  1021.    if((*PLANE_current_element).before != 0) {
  1022.      (*(*PLANE_current_element).before).next = PLANE_element;
  1023.    }
  1024.    (*PLANE_current_element).before = PLANE_element;         
  1025.  
  1026.    PLANE_current_element = PLANE_element;
  1027.    
  1028.    if((*PLANE_element).before == NULL) {
  1029.      PLANE_first_element = PLANE_element;
  1030.    } 
  1031.  
  1032.    PLANE_length++;
  1033. /*
  1034.    LINK_current_element = LINK_first_element; 
  1035.  
  1036.    while(LINK_current_element) {
  1037.      if((*LINK_current_element).SOURCE.plane >= PLANE_no) {
  1038.        (*LINK_current_element).SOURCE.plane++;
  1039.      }
  1040.      if((*LINK_current_element).TARGET.plane >= PLANE_no) {
  1041.        (*LINK_current_element).TARGET.plane++;
  1042.      }
  1043.      LINK_current_element = (*LINK_current_element).next;
  1044.    }
  1045.  
  1046.    LINK_current_element = LINK_last_element;
  1047. */
  1048.  }
  1049. }
  1050.  
  1051. /*****************************************************************************
  1052.   FUNCTION : overwrite_plane
  1053.  
  1054.   PURPOSE  : overwrites the current plane element (Current Plane) with the 
  1055.              datas of the plane editor (Edit Plane).
  1056.  
  1057.   NOTES    : 
  1058.   RETURNS  :
  1059.  
  1060.   UPDATE   : 20.12.1991
  1061. ******************************************************************************/
  1062.  
  1063. static void overwrite_plane(void)
  1064.  
  1065. {
  1066.  if(PLANE_length == 0) {
  1067.    enter_plane();
  1068.  }
  1069.  else {
  1070.    (*PLANE_current_element).width = PLANE_width;
  1071.    (*PLANE_current_element).height = PLANE_height;
  1072.    (*PLANE_current_element).pos = PLANE_pos;
  1073.    (*PLANE_current_element).type = PLANE_type;
  1074.  
  1075. /*   get_links_and_delete_them(PLANE_no);
  1076.  
  1077.    LINK_current_element = LINK_first_element;
  1078. */
  1079.  }
  1080. }
  1081.  
  1082. /*****************************************************************************
  1083.   FUNCTION : delete_current_plane
  1084.  
  1085.   PURPOSE  : deletes Currenrt Plane out of the plane list.
  1086.  
  1087.   NOTES    : 
  1088.   RETURNS  :
  1089.  
  1090.   UPDATE   : 20.12.1991
  1091. ******************************************************************************/
  1092.  
  1093. static void delete_current_plane(void)
  1094.  
  1095. {
  1096.  PLANE *PLANE_element;
  1097.  
  1098.  PLANE_element = PLANE_current_element;
  1099.  
  1100.  /* Delete the element "PLANE_element" out of the plane-list */
  1101.  
  1102.  if(PLANE_length != 0) {
  1103.    if((*PLANE_element).before != NULL) {
  1104.      (*(*PLANE_element).before).next = (*PLANE_element).next;
  1105.    }
  1106.    if((*PLANE_element).next != NULL) {
  1107.      (*(*PLANE_element).next).before = (*PLANE_element).before;
  1108.    }
  1109.  
  1110.    /* Delete all the links which are connected with the deleted plane */
  1111.    
  1112. /*   get_links_and_delete_them(PLANE_no);
  1113.  
  1114.    LINK_current_element = LINK_first_element;
  1115. */
  1116.    /* Decrement the number of the Planes */
  1117.  
  1118. /*   while(LINK_current_element) {
  1119.      if((*LINK_current_element).SOURCE.plane > PLANE_no) {
  1120.        (*LINK_current_element).SOURCE.plane--;
  1121.      }
  1122.      if((*LINK_current_element).TARGET.plane > PLANE_no) {
  1123.        (*LINK_current_element).TARGET.plane--;
  1124.      }
  1125.      LINK_current_element = (*LINK_current_element).next;
  1126.    }
  1127.  
  1128.    LINK_current_element = LINK_last_element;
  1129. */
  1130.    PLANE_length--;
  1131.  
  1132.    /* Update the three pointers "PLANE_current_element", "PLANE_first_element"
  1133.       "PLANE_last_element."  */
  1134.  
  1135.    if(PLANE_length == 0){
  1136.      PLANE_current_element = NULL;
  1137.      PLANE_first_element   = NULL;
  1138.      PLANE_last_element    = NULL;
  1139.      PLANE_no--;
  1140.    }
  1141.    else if((*PLANE_element).next == NULL) {
  1142.      PLANE_current_element = (*PLANE_element).before;
  1143.      PLANE_last_element    = PLANE_current_element;
  1144.      PLANE_no--;
  1145.    }
  1146.    else if((*PLANE_element).before == NULL) {
  1147.      PLANE_current_element = (*PLANE_element).next;
  1148.      PLANE_first_element   = PLANE_current_element;
  1149.    }
  1150.    else {
  1151.      PLANE_current_element = (*PLANE_element).next;
  1152.    }
  1153.  
  1154.    free(PLANE_element);
  1155.  }
  1156. }
  1157.  
  1158. /*****************************************************************************
  1159.   FUNCTION : forward_plane
  1160.  
  1161.   PURPOSE  : moves forward one list element in the plane list.
  1162.  
  1163.   NOTES    : 
  1164.   RETURNS  : Error = 0 ; Succes = 1
  1165.  
  1166.   UPDATE   : 20.12.1991
  1167. ******************************************************************************/
  1168.  
  1169. static int forward_plane(void)
  1170.  
  1171. {
  1172.  if(PLANE_length != 0) {
  1173.    if((*PLANE_current_element).next != NULL) {
  1174.      PLANE_current_element = (*PLANE_current_element).next;
  1175.      PLANE_no++;
  1176.    }
  1177.    return 1;
  1178.  }
  1179.  else {
  1180.   return 0;
  1181.  }
  1182. }
  1183.  
  1184. /*****************************************************************************
  1185.   FUNCTION : backward_link
  1186.  
  1187.   PURPOSE  : moves backward one plane element in the link list.
  1188.  
  1189.   NOTES    : 
  1190.   RETURNS  : Error = 0 ; Succes = 1
  1191.  
  1192.   UPDATE   : 20.12.1991
  1193. ******************************************************************************/
  1194.  
  1195. static int backward_plane(void)
  1196.  
  1197. {
  1198.  if(PLANE_length != 0) {
  1199.    if((*PLANE_current_element).before != NULL) {
  1200.      PLANE_current_element = (*PLANE_current_element).before;
  1201.      PLANE_no--;
  1202.    }
  1203.    return 1;
  1204.  }
  1205.  else {
  1206.    return 0;
  1207.  }
  1208. }
  1209.  
  1210. /*****************************************************************************
  1211.   FUNCTION : beginning_plane
  1212.  
  1213.   PURPOSE  : jumps to the beginning of the plane list.
  1214.  
  1215.   NOTES    : 
  1216.   RETURNS  : Error = 0 ; Succes = 1
  1217.  
  1218.   UPDATE   : 20.12.1991
  1219. ******************************************************************************/
  1220.  
  1221. static int beginning_plane(void)
  1222.  
  1223. {
  1224.  if(PLANE_length != 0){
  1225.    PLANE_current_element = PLANE_first_element;
  1226.    PLANE_no = 1;
  1227.    return 1;
  1228.  }
  1229.  else {
  1230.   return 0;
  1231.  }
  1232. }
  1233.  
  1234. /*****************************************************************************
  1235.   FUNCTION : end_plane
  1236.  
  1237.   PURPOSE  : jumps to the end of the plane list.
  1238.  
  1239.   NOTES    : 
  1240.   RETURNS  : Error = 0 ; Succes = 1
  1241.  
  1242.   UPDATE   : 20.12.1991
  1243. ******************************************************************************/
  1244.  
  1245. static int end_plane(void)
  1246.  
  1247. {
  1248.  if(PLANE_length != 0) {
  1249.    PLANE_current_element = PLANE_last_element;
  1250.    PLANE_no = PLANE_length;
  1251.    return 1;
  1252.  }
  1253.  else {
  1254.    return 0;
  1255.  }
  1256. }
  1257.  
  1258. /*****************************************************************************
  1259.   FUNCTION : get_plane
  1260.  
  1261.   PURPOSE  : returns a pointer to the plane element "plane_no"
  1262.  
  1263.   NOTES    : 
  1264.   RETURNS  : returns a pointer to the plane element "plane_no" 
  1265.  
  1266.   UPDATE   : 20.12.1991
  1267. ******************************************************************************/
  1268.  
  1269. static PLANE *get_plane(int plane_no)
  1270.  
  1271. {
  1272.  PLANE *PLANE_element = PLANE_first_element;
  1273.  int counter = 1;
  1274.  
  1275.  while((PLANE_element != NULL) &&
  1276.        (counter != plane_no)) {
  1277.    counter++;
  1278.    PLANE_element = (*PLANE_element).next;
  1279.           
  1280.  }/*while*/
  1281.  return PLANE_element;
  1282. }/*get_plane*/
  1283.  
  1284.  
  1285. /*****************************************************************************
  1286.  
  1287. ******************************************************************************/
  1288.  
  1289. /* end of file */
  1290. /* lines: 2710 */
  1291.  
  1292.  
  1293.  
  1294.